<!--归档-->
<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="car-label">关键字:</div>
      <el-input v-model="listQuery.keyString" placeholder="Title" style="width: 180px;" class="filter-item" />
      <div class="car-label">放款时间:</div>
      <el-date-picker v-model="listQuery.bankLoanDate" placeholder="请选择放款时间" clearable style="width: 130px" class="filter-item" />
      <div class="car-label">归档状态:</div>
      <el-select v-model="listQuery.filingStatus" placeholder="请选择" clearable class="filter-item" style="width: 130px">
        <el-option v-for="item in statuses" :key="item.key" :label="item.lable" :value="item.key" />
      </el-select>
      <div class="car-label">贷款银行:</div>
      <el-select v-model="listQuery.bank" style="width: 140px" class="filter-item">
        <el-option v-for="item in banks" :key="item.id" :label="item.bankName" :value="item.id" />
      </el-select>
      <el-button  style="margin-left: 10px" class="filter-item" type="primary" icon="el-icon-search" @click="search">
        搜索
      </el-button>
      <el-button class="filter-item right-btn" type="primary" icon="el-icon-plus" @click="toDetail">
        归档
      </el-button>
    </div>
    <ve-table
      style="width:100%"
      :columns="columns"
      :table-data="tableData"
      :border-x="true"
      row-key-field-name="id"
      :border-y="true"
      :row-style-option="rowStyleOption"
      :checkbox-option="checkboxOptipon"
    />
    <div class="table-pagination">
      <ve-pagination
        :total="totalCount"
        :page-index="pageIndex"
        :page-size="pageSize"
        @on-page-number-change="pageNumberChange"
        @on-page-size-change="pageSizeChange"
      />
    </div>
  </div>
</template>

<style scoped lang="scss">
  .table-pagination {
    margin-top: 20px;
    text-align: right;
  }
  .right-btn{
    float: right;
  }
</style>

<script>

export default {
  data() {
    return {
      // page index
      pageIndex: 1,
      // page size
      pageSize: 10,
      tableData: [],
      totalCount: 1,
      banks:[],
      statuses:[{key:0,label:"待归档"},{key:1,label:"待审核"}],
      listQuery: {},
      rowStyleOption: { // 表格样式
        stripe: true, // 斑马纹
        hoverHighlight: true, // hover高亮
        clickHighlight: true // 点击行高亮
      },
      checkboxOptipon: {
        // 行选择改变事件
        selectedRowChange: ({ row, isSelected, selectedRowKeys }) => {
          console.log(row, isSelected, selectedRowKeys)
        },
        // 全选改变事件
        selectedAllChange: ({ isSelected, selectedRowKeys }) => {
          console.log(isSelected, selectedRowKeys)
        }
      },
      columns: [
        {
          field: '',
          key: '1',
          // type=checkbox
          type: 'checkbox',
          title: '',
          width: 50,
          align: 'center'
        },
        {
          field: 'id',
          key: 'a',
          title: '序号',
          width: '150px',
          align: 'center'
        },
        { field: 'orderId', key: 'b', title: '订单编号', align: 'center', width: '100px' },
        { field: 'mainUser', key: 'c', title: '客户姓名', align: 'left', width: '100px' },
        { field: 'loanAmount', key: 'd', title: '贷款金额', width: '' },
        { field: 'department', key: 'e', title: '部门', width: '' },
        { field: 'serviceUser', key: 'f', title: '业务员', width: '' },
        { field: 'filingStatus', key: 'g', title: '状态', width: '' },
        { field: 'address', key: 'h', title: '归档类型', width: '' },
        { field: 'companyDataFilingDate', key: 'i', title: '公司签约资料', width: '' },
        { field: 'keyFilingDate', key: 'j', title: '钥匙留存', width: '' },
        { field: 'address', key: 'k', title: '车资原件', width: '' },
        { field: 'carDataFilingDate', key: 'l', title: '贷款银行', width: '' },
        { field: 'bankLoanDate', key: 'm', title: '银行放款时间', width: '' },
        { field: 'pledgeDate', key: 'n', title: '抵押日期', width: '' }
      ]
    }
  },
  computed: {
  },
  created() {
    this.appId = sessionStorage.getItem("appId");
    this.initDatabase();
    this.getBankList();
  },
  methods: {
    toDetail () {
      this.$router.push({
        name:'fileInform',
        query: {}
      })
    },
    search(){
      this.pageIndex = 1;
      this.initDatabase();
    },
    pageNumberChange(pageIndex) {
      this.pageIndex = pageIndex
      this.initDatabase();
    },

    pageSizeChange(pageSize) {
      this.pageIndex = 1;
      this.pageSize = pageSize;
      this.initDatabase();
    },
    /**
       * 获取银行列表数据
       * @date 2021-05-18
       */
      async getBankList () {
        let param = {appId: await sessionStorage.getItem("appId")};
        let data = await this.$http.post('/auth/bankSetup/listAll', param);
        if (data.code === 200) {
          this.banks = data.data;
        }
      },
    /**
     * 初始化数据
     * @date 2021-05-10
     */
    async initDatabase() {

      this.tableData = [];
      this.listQuery.appid = this.appId;

      let data = await this.$http.post('/flow/filing/list/'+ this.pageIndex + "/" + this.pageSize, this.listQuery)
      console.log(data);
      if (data.code === 200) {
        this.tableData = data.data.records;
        this.totalCount = data.data.total;
      } else {
      this.$message({
        type: 'error',
        message: '查询失败，请刷新页面'
      });
      }

      console.log(this.tableData)
    },
    /**
     * 禁用
     * @param {Object} row
     */
    async forbidorDealer(row) {
      let that = this
      this.$alert('是否确认禁用', '确认禁用', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          that.formData = row;
          if (row.status === 1) {
            that.formData.status = 0;
          } else {
            that.formData.status = 1;
          }
          let data = await that.$http.post('/auth/distributor/update', that.formData)
          console.log(data);
          if (data.code === 200) {
            that.initDatabase();
          } else {
            that.$message({
              type: 'error',
              message: '操作失败'
            });
          }
        }).catch(() => {
        that.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },

    /**
     * 删除
     * @param {Object} row
     */
    async deleteorDealer(row) {

      let that = this

      this.$alert('是否确认删除', '确认删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        let data = await that.$http.delete('/auth/distributor/delete/' + row.id, {})
        console.log(data);
        if (data.code === 200) {
          that.initDatabase();
        } else {
          that.$message({
            type: 'info',
            message: '操作失败，请重试'
          });
        }
      })
    },

    /**
     * 编辑
     * @date 2021-05-08
     * @param row
     */
    editorDealer(row) {
      this.formData = row
      this.newDialog = true
      this.editorFlag = true // 编辑标识
      this.dialogTitle = '编辑经销商'
    },
    /**
     * 点击新增按钮
     * @date 2021-05-08
     */
    toAdd() {
      this.formData = {}
      this.newDialog = true
      this.editorFlag = false  // 编辑标志
      this.dialogTitle = '新增经销商'
    },
    /**
     * 编辑操作
     * @date 2021-05-17
     */
    editorData () {

    },
    /**
     * 新增操作
     * @date 2021-05-08
     */
    async addData() {
      this.$refs['mainForm'].validate(async (valid) => {
        if (valid) {
          if (this.formData.id) {
            let data = await this.$http.post('/auth/distributor/update', this.formData)
            console.log(data);
            if (data.code === 200) {
              this.newDialog = false;
              this.initDatabase();
            } else {
              this.$message({
                type: 'info',
                message: '操作失败，请重试'
              });
            }
          } else {
            this.formData.appId = this.appId;
            let data = await this.$http.post('/auth/distributor/save', this.formData)
            if (data.code === 200) {
              this.newDialog = false;
              this.initDatabase();
            } else {
              this.$message({
                type: 'info',
                message: '操作失败，请重试'
              });
            }
          }
        }
      })
    }
  }
}
</script>
